<template>
    <div id="tmpl">
        <div id="title">
            <h4 v-text="info.title"></h4>
            <p>{{info.add_time|timeFormat('YYYY-MM-DD')}} 浏览数:{{ info.click }}</p>
        </div>
        <div id="content" v-html="info.content"></div>

        <!--实现评论子组件-->
        <!--将id值传给子组件-->
        <comment :id="id"></comment>

    </div>
</template>

<script>
    //引入子组件，评论组件
    import comment from '../subcom/comment.vue';

  export default{
//    注册评论子组件
    components:{
      comment,
    },
    data(){
      return {
        id: 0,
        info: {}
      }
    },
    created(){
      this.id = this.$route.params.id;
      this.getinfo();
    },
    methods: {
      getinfo(){
//        获取数据地址
        var url = 'http://webhm.top:8899/api/getnew/' + this.id;
        //发送请求
        this.$http.get(url).then(function (response) {
//          将返回的参数传给info
          this.info = response.body.message[0];
        })
      }
    }
  }
</script>

<style scoped>
    #title, #content {
        padding: 5px;
    }

    #title p {
        color: rgba(0, 0, 0, 0.4);
    }

    #content {
        color: black;
    }
</style>